Option Strict On Option Explicit On Public Class Form1 Const queenPts As Integer = 13 Const numHearts As Integer = 13 Const moonPts As Integer = 26 Private Sub ClearHand() txtHearts1.Clear() txtHearts2.Clear() txtHearts3.Clear() txtHearts4.Clear() radQueen1.Checked = True radQueen2.Checked = False radQueen3.Checked = False radQueen4.Checked = False txtPoints1.Clear() txtPoints2.Clear() txtPoints3.Clear() txtPoints4.Clear() End Sub Private Sub UpdateTotal(ByVal newPts As Integer, ByRef total As String) Dim pts As Integer Dim isconverted As Boolean ' convert isconverted = Integer.TryParse(total, pts) ' add pts = pts + newPts ' display total = pts.ToString() End Sub Private Function calcScore(ByVal hearts As Integer, ByVal queen As Boolean) As Integer Dim score As Integer score = hearts ' add points if they have the quuen of spades If queen Then score = score + queenPts End If ' check for "shooting the moon" If score = moonPts Then score = -1 * moonPts End If Return score End Function Private Function validateHearts(ByVal heartStr As String, ByRef hearts As Integer, ByVal min As Integer, ByVal max As Integer, ByVal what As String) As Boolean Dim isConverted As Boolean isConverted = Integer.TryParse(heartStr, hearts) If isConverted Then If hearts >= min AndAlso hearts <= max Then Return True Else MsgBox(what & " needs to be between " & min & " and " & max) Return False End If Else MsgBox(what & " needs to be a whole number") Return False End If End Function Private Function checkHeartTotal(ByVal hearts1 As Integer, ByVal hearts2 As Integer, ByVal hearts3 As Integer, ByVal hearts4 As Integer) As Boolean Dim total As Integer total = hearts1 + hearts2 + hearts3 + hearts4 If total = numHearts Then ' valid inputs Return True Else MsgBox("The total number of hearts won by all players MUST add up to 13") Return False End If End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click ClearHand() End Sub Private Sub BtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReset.Click ClearHand() txtTotal1.Text = "0" txtTotal2.Text = "0" txtTotal3.Text = "0" txtTotal4.Text = "0" End Sub Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click Dim points1 As Integer Dim points2 As Integer Dim points3 As Integer Dim points4 As Integer Dim hearts1 As Integer Dim hearts2 As Integer Dim hearts3 As Integer Dim hearts4 As Integer Dim isValid1 As Boolean Dim isValid2 As Boolean Dim isValid3 As Boolean Dim isValid4 As Boolean Dim isCompatible As Boolean isValid1 = validateHearts(txtHearts1.Text, hearts1, 0, queenPts, "Player 1 Hearts") isValid2 = validateHearts(txtHearts2.Text, hearts2, 0, queenPts, "Player 2 Hearts") isValid3 = validateHearts(txtHearts3.Text, hearts3, 0, queenPts, "Player 3 Hearts") isValid4 = validateHearts(txtHearts4.Text, hearts4, 0, queenPts, "Player 4 Hearts") If isValid1 AndAlso isValid2 AndAlso isValid3 AndAlso isValid4 Then isCompatible = checkHeartTotal(hearts1, hearts2, hearts3, hearts4) If isCompatible Then ' inputs are valid and compatible ' calculate points points1 = calcScore(hearts1, radQueen1.Checked) txtPoints1.Text = points1.ToString() ' update total UpdateTotal(points1, txtTotal1.Text) ' calculate points for player 2 points2 = calcScore(hearts2, radQueen2.Checked) txtPoints2.Text = points2.ToString() ' update total UpdateTotal(points2, txtTotal2.Text) ' calculate points for player 3 points3 = calcScore(hearts3, radQueen3.Checked) txtPoints3.Text = points3.ToString() ' update total UpdateTotal(points3, txtTotal3.Text) ' calculate points for player 4 points4 = calcScore(hearts4, radQueen4.Checked) txtPoints4.Text = points4.ToString() ' update total UpdateTotal(points4, txtTotal4.Text) End If End If End Sub End Class